<div class="list-order">
    <table>
        <tr class="header">
            <th width="50px">STT</th>
            <th width="150px">Tên khách hàng</th>
            <th width="200px">Địa chỉ</th>
            <th width="100px">Số điện thoại</th>
            <th width="150px">Email</th>
            <th width="100px">Ngày đặt hàng</th>
            <th width="150px">Trạng thái</th>
            <th width="100px">Chi tiết</th>
            <th width="50px">Xóa</th>
        </tr>
        <?php $count = 1; foreach ($this->orders as $item_order){?>
        <tr>
            
            <td style="text-align: center"><?php echo $count?></td>
            <td><?php echo $item_order['order_guessname_delivery']?></td>
            <td><?php echo $item_order['order_guessaddress_delivery']?></td>
            <td><?php echo $item_order['order_guessphone_delivery']?></td>
            <td style="text-align: center"><?php echo $item_order['order_guessemail_delivery']?></td>
            <td style="text-align: center"><?php $date = date_create($item_order['order_datecreated']); echo date_format($date, 'd-m-Y');?></td>
            <td style="text-align: center">
                <select class="<?php echo $item_order['order_id']?>">
                    <option value="0" <?php if($item_order['order_state'] == 0) echo 'selected'; else echo ''?>>Chưa xác nhận</option>
                    <option value="1" <?php if($item_order['order_state'] == 1) echo 'selected'; else echo ''?>>Đã xác nhận</option>
                </select>
            </td>
            <td style="text-align: center"><a href="<?php echo $this->baseUrl('admin/order/detail/id/').$item_order['order_id']?>" title="Chi tiết đơn hàng">Xem</a></td>
            <td style="text-align: center">
                <a class="del" href="<?php echo  $this->baseUrl('admin/order/delete/id/') .$item_order['order_id']?>" title="Xóa đơn hàng">
                    <img src="<?php echo $this->baseUrl('admin/images/remove.ico')?>" alt="del"/>
                </a>
            </td>
        </tr>
        <?php
        $count++;
        }?>
    </table>
            <?php if($this->orders->Count() > 1) {?>                
            <div id="paginator">
                 <?php echo $this->paginationControl($this->orders, 'Sliding', 'index/pagination.phtml')?>
            </div>
            <?php }?>
            <div class="dialog" title="Thông báo"></div>
</div>

<script>
//update state of order
$(function(){
	$(".list-order select").change(function(){
	    var link = "<?php echo $this->url(array('module'=>'admin', 'controller'=>'order', 'action'=>'changestate'))?>";
	    var rdata = {"param": {"id": $(this).attr("class"), "state": $(this).val()}};
// 	    alert($(this).attr("class"));
	    $.ajax({
		    url: link,
		    data: rdata,
		    });
	    return false;
		});
});

//delete order
$(function(){
	$(".list-order table td a.del").click(function(){
		var _this=$(this);
        $(".dialog").html('<div class="message"><p>Bạn có chắc muốn xóa đơn hàng này?</p></div>')
        .dialog({
            width: 350,
            resizable: false,
            modal: true,
            buttons: {
                "Có": function(){
                	var link = _this.attr("href");
                    $.ajax({
                        url: link,
                        }); 
                    _this.parent().parent().remove();                    
                    $(this).dialog("close");
                    },
                    "Không": function(){
                        $(this).dialog("close");
                        }
                }
            });
        return false;
		});
});

//fill background for row of table
$(function(){
	$(".list-order table tr").filter(":odd").addClass("alt");
});
</script>